subroutine record_nstop(nlog,nout)
  use param
  use global
  implicit none
  integer,intent(in) :: nlog,nout
  integer :: i,j,td
  real(dbl) :: e,r,h
  integer :: pos,atd
  pmine=0.0
  if (pmode.eq.1) then
     ! ------------------------------------------- !
     ! Set min,max
     pmaxe=egrid(n_egrid)
     ! pmine
     td=1
     ! tgrid
     if (egrid(1).eq.0) then
        td=td+nhp*n_rspec
     else
        td=td+nhp*(n_rspec+1)
     end if
     r=real(td)
     ! ------------------------------------------- !
     open(unit=nout,file=outfn,access='direct',status='replace',recl=8)
     ! -- file info
     pos=0
     atd=0
     call dwrite(nout,pos,pmine)
     call dwrite(nout,pos,pmaxe)
     call dwrite(nout,pos,r)
     write(nlog,'(3x,"Minimum energy=",1pe9.3)') pmine
     write(nlog,'(3x,"Maximum energy=",1pe9.3)') pmaxe
     write(nlog,'(3x,"Number of grids=",i0)') td
     write(*,'(3x,"Minimum energy=",1pe9.3)') pmine
     write(*,'(3x,"Maximum energy=",1pe9.3)') pmaxe
     write(*,'(3x,"Number of grids=",i0)') td
     ! -- initial
     e=pmine
     r=0.0
     call dwrite(nout,pos,e)
     call dwrite(nout,pos,r)
     atd=atd+1
     write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
     write(*,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
     if (egrid(1).eq.0) then
        do i=1,n_rspec
           h=(egrid(i+1)-egrid(i))/real(nhp)
           e=egrid(i)
           do j=1,nhp
              e=e+h
              call get_nstop(e,nip,r)
              call dwrite(nout,pos,e)
              call dwrite(nout,pos,r)
              atd=atd+1
              write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
              write(*,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
           end do
        end do
     else
        h=egrid(1)/real(nhp)
        do i=1,nhp
           e=e+h
           call get_nstop(e,nip,r)
           call dwrite(nout,pos,e)
           call dwrite(nout,pos,r)
           atd=atd+1
           write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
           write(*,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
        end do
        do i=1,n_rspec
           h=(egrid(i+1)-egrid(i))/real(nhp)
           e=egrid(i)
           do j=1,nhp
              e=e+h
              call get_nstop(e,nip,r)
              call dwrite(nout,pos,e)
              call dwrite(nout,pos,r)
              atd=atd+1
              write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
              write(*,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
           end do
        end do
     end if
     write(nlog,'(3x,"Total number of data : Recorded=",i0,3x,"Counted=",i0 )') td,atd
     write(*,'(3x,"Total number of data : Recorded=",i0,3x,"Counted=",i0 )') td,atd
     close(nout)
  else if (pmode.eq.2) then
     ! ------------------------------------------- !
     ! pmine
     td=1
     ! pgrid
     if (peh.lt.pih) pih=0.2*peh
     td=td+int((pmaxe-pmine)/peh)
     ! pmaxe
     if (mod(pmaxe-pmine,peh).ne.0) td=td+1
     r=real(td)
     ! ------------------------------------------- !
     open(unit=nout,file=outfn,access='direct',status='replace',recl=8)
     ! -- file info
     pos=0
     atd=0
     call dwrite(nout,pos,pmine)
     call dwrite(nout,pos,pmaxe)
     call dwrite(nout,pos,r)
     write(nlog,'(3x,"Minimum energy(2*a)=",1pe9.3)') pmine
     write(nlog,'(3x,"Maximum energy=",1pe9.3)') pmaxe
     write(nlog,'(3x,"Number of grids=",i0)') td
     write(*,'(3x,"Minimum energy(2*a)=",1pe9.3)') pmine
     write(*,'(3x,"Maximum energy=",1pe9.3)') pmaxe
     write(*,'(3x,"Number of grids=",i0)') td
     ! -- initial
     e=pmine
     r=0.0
     call dwrite(nout,pos,e)
     call dwrite(nout,pos,r)
     atd=atd+1
     write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
     ! -- middle
     do i=2,td-1
        e=e+peh
        call get_nstop(e,nip,r)
        call dwrite(nout,pos,e)
        call dwrite(nout,pos,r)
        write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
        write(*,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
        atd=atd+1
     end do
     ! -- final
     e=pmaxe
     call get_nstop(e,nip,r)
     call dwrite(nout,pos,e)
     call dwrite(nout,pos,r)     
     write(nlog,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
     write(*,'(3x,"E=",1pe9.3,1x,"Xsec=",1pe9.3)') e,r
     atd=atd+1
     write(nlog,'(3x,"Total number of data : Recorded=",i0,3x,"Counted=",i0 )') td,atd
     write(*,'(3x,"Total number of data : Recorded=",i0,3x,"Counted=",i0 )') td,atd
     close(nout)
  else
     stop
  end if
end subroutine record_nstop
